<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class login extends CI_Controller {

	function __construct(){
		parent::__construct();
		$this->load->helper(array('url','date','form'));
		$this->load->library('auth');
	}
	
	public function index()
	{
		$this->load->library('layouts');
	
		$this->layouts->add_includes('jqwidgets/jqxcore.js')
     				  ->add_includes('jqwidgets/jqxbuttons.js')              
					  ->add_includes('jqwidgets/jqxinput.js');           
		
		$this->layouts->set_title('Property Management');
		$this->layouts->set_description('Property xx Management');
	 
	 	$this->layouts->view('login_view',array('view_name1'=>'signin_view','view_name2'=>'website_view'),null,true);
	}
	
	public function login_process()
	{
		$username = $this->input->post('username');
		$password = $this->input->post('password'); 
		$success = $this->auth->do_login($username,$password);
		if($success)
		{
			//jika berhasil larikan ke controller home
			redirect('home');
		}else{
			//jika gagal larikan ke login
			redirect('login');
		}
	}
	
	function logout()
	{
		if($this->auth->is_logged_in() == true)
		{
			// jika dia memang sudah login, destroy session
			$this->auth->do_logout();
		}
		// larikan ke halaman utama
		redirect('login','refresh');
	}

}